/* 测试my_exception.h 内相关
 * 
 * */
#include <exception/spw_exception.h>
#include <exception/spw_stdexcept.h>
#include <stdio.h>
#include <gtest/gtest.h>
#include <gtest/gtest-death-test.h>
#include <gtest/gtest-spi.h>
using namespace spwstd;

// 当抛出异常spwexcept::ception 捕获异常e, e.what()返回"mystd::exception"字符串
// class ExceptionTest : public ::testing::Test {
// protected:
//     void SetUp() override {
//         try{
//             throw spwexcept::ception();
//         } catch(spwexcept::ception& ee) {
//             e = ee;
//         }
//     }
//
//     spwexcept::ception e;
//
// };
TEST(ExceptionTest, What) {
    spwexcept::Exception e;
    EXPECT_STREQ(e.what(), "spwstd::spwexcept::Exception");
}

TEST(RuntimeErrorTest, runtimeerrortest)
{
    using namespace spwexcept;
    RuntimeError re("this is runtime error");
    EXPECT_STREQ(re.what(), "this is runtime error");
    RuntimeError re1(re);
    EXPECT_STREQ(re1.what(), "this is runtime error");
    RuntimeError re2("this is runtime error 2");
    re1 = re2;
    EXPECT_STREQ(re1.what(), "this is runtime error 2");
}

TEST(LogicErrorTest, logicerrortest)
{
    using namespace spwexcept;
    LogicError le("this is logic error");
    EXPECT_STREQ(le.what(), "this is logic error");
    LogicError le1(le);
    EXPECT_STREQ(le1.what(), "this is logic error");
    LogicError le2("this is logic error 2");
    le1 = le2;
    EXPECT_STREQ(le1.what(), "this is logic error 2");
}

// dead test
// 1. not catch the exception
void not_catch_except() {
    throw spwexcept::Exception();
}

TEST(ExceptionTest, not_catch_except) {
    EXPECT_NONFATAL_FAILURE( EXPECT_DEATH(not_catch_except(), ""), "");
}

int main(int argc, char* argv[]){
    ::testing::InitGoogleTest(&argc, argv);
    return RUN_ALL_TESTS();
}
